package com.example.a517;

import android.os.Bundle;
import android.util.Log;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import org.json.JSONObject;

public class JSONTest extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_jsontest);
        String json = "{\n" +
                "  \"person\": {\n" +
                "    \"name\": \"John\",\n" +
                "    \"age\": 30,\n" +
                "    \"city\": \"New York\"\n" +
                "  }\n" +
                "}";
        try {
            JSONObject jsonObject = new JSONObject(json);
            JSONObject person = jsonObject.getJSONObject("person");
            String name = person.getString("name");
            String age = person.getString("age");
            String city = person.getString("city");

            Log.e("TAG", "onCreate: "+name );
            Log.e("TAG", "onCreate: "+age );
            Log.e("TAG", "onCreate: "+city );
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}